﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DC2010.Objects;
using DC2010;

namespace DC2010_Editor.Controls.Utils
{
    public enum OpenType
    {
        Create = 0,
        Edit = 1
    }

    public partial class CreateNewMapForm : Form
    {
        public OpenType ot { get; set; }
        public Map data { get; set; }

        public CreateNewMapForm()
        {
            InitializeComponent();
            ot = OpenType.Edit;
        }

        public CreateNewMapForm(OpenType ot, Map m)
            : this()
        {
            this.ot = ot;
            data = m;

            //if (ot == OpenType.Create) data = new Map();
        }

        private void CreateNewMapForm_Load(object sender, EventArgs e)
        {
            if (data != null)
            {
                seTextBox1.SetRelatedObject(data.Info.GlobalEffects, EffectType.Pump);
                inventoryTextBox1.SetRelatedObject(data.Info.LinkedObjects);

                ItemIdTextBox.Text = data.Info.Id;
                numericUpDown1.Value = data.X;
                numericUpDown2.Value = data.Y;
            }
            else
            {
                seTextBox1.Enabled = false;
                inventoryTextBox1.Enabled = false;
            }

            Refresh();
        }

        private void Refresh()
        {
 
        }

        private void SaveFloorButton_Click(object sender, EventArgs e)
        {
            string sMapId = ItemIdTextBox.Text;
            int iX = (int)numericUpDown1.Value;
            int iY = (int)numericUpDown2.Value;

            if (ot == OpenType.Create)
            {
                Map m = new Map(sMapId, iX, iY);
                Root.I.MapSystem.AddToSystem(m, m.Info.Id, ObjectTarget.Instance);
                Root.I.MapSystem.SaveInstance();
                Close();
            }
            else
            {
                data.Info.Id = sMapId;
                Root.I.MapSystem.SaveInstance();
                Close();
            }
        }
    }
}
